const connection = require('../app/database')
class LabelService {
  async create(name) {
    const statement = 'INSERT INTO `label` (name) VALUES(?);'
    const result = await connection.execute(statement, [name])
    return result
  }
  async queryList(offset = 0, size = 10) {
    const statement = `SELECT * FROM label LIMIT ? OFFSET ?;`
    const [values] = await connection.execute(statement, [
      String(size),
      String(offset),
    ])
    return values
  }
  async queryLabelByName(name) {
    const statement = `SELECT * FROM label WHERE name= ?;`
    const [values] = await connection.execute(statement, [name])
    console.log(values)
    return values[0]
  }
  async addLabel(momentId, labelId) {
    const statement = `INSERT INTO moment_label (moment_id,label_id) VALUES(?,?);`
    const [values] = await connection.execute(statement, [momentId, labelId])
    // console.log(values)
    return values
  }
  async remove(labelId){
    const statement = 'DELETE FROM label WHERE id=?;'
    const [values] = await connection.execute(statement, [labelId])
    return values
  }
  async updteById(name,labelId){
    const statement = 'UPDATE `label` SET name=? WHERE id=?;'
    const [values] = await connection.execute(statement, [name, labelId])
    return values
  }
}
module.exports = new LabelService()
